package vashion.azeroth.core.query;

import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;

public class BaseQuery {
	
    Integer PAGE_SIZE = 3;           // 每页数量
    Integer DEFAULT_PAGE_NUMBER = 0; // 默认当前页码
	
    protected Integer pageSize;
    protected Integer pageNum;
    
    public Pageable getPageable() {
        if (pageSize == null || pageSize <= 0) {
            pageSize = PAGE_SIZE;
        }
        if (pageNum == null || pageNum < DEFAULT_PAGE_NUMBER) {
        	pageNum = DEFAULT_PAGE_NUMBER;
        }
    	Pageable pageable = new PageRequest(pageNum, pageSize);
    	
    	return pageable;
    }
    
	public Integer getPageSize() {
		return pageSize;
	}
	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getPageNum() {
		return pageNum;
	}
	public void setPageNum(Integer pageNum) {
		this.pageNum = pageNum;
	}
    
    
}
